﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class UIMain : UIDialog
{

    public Text ShitNum;
    public Text SunNum;
    public Text TimeRecord;
    public Button WaitResource;

    void Start()
    {
        ShitNum = GameObject.Find("shitNum").GetComponent<Text>();
        ShitNumRefresh();
        SunNum = GameObject.Find("sunNum").GetComponent<Text>();
        SunNumRefresh();
        TimeRecord = GameObject.Find("timeRecord").GetComponent<Text>();
        TimeRecordRefresh();
        WaitResource = GameObject.Find("Wait").GetComponent<Button>();
        WaitResource.onClick.AddListener(WaitRes);
    }

    void OnEnable()
    {
        PlayerData.Instance.SunNumRefresh = SunNumRefresh;
        PlayerData.Instance.ShitNumRefresh = ShitNumRefresh;
        PlayerData.Instance.RoundRefresh = TimeRecordRefresh;
    }

    void OnDisable()
    {
        PlayerData.Instance.SunNumRefresh -= SunNumRefresh;
        PlayerData.Instance.ShitNumRefresh -= ShitNumRefresh;
        PlayerData.Instance.RoundRefresh -= TimeRecordRefresh;
    }

    void ShitNumRefresh()
    {
        ShitNum.text = string.Format("X{0}", PlayerData.Instance.ShitNum);
    }

    void SunNumRefresh()
    {
        SunNum.text = string.Format("X{0}", PlayerData.Instance.SunNum);
    }

    void TimeRecordRefresh()
    {
        TimeRecord.text = string.Format("{0}/{1}", PlayerData.Instance.Round, Const.MaxRound);
    }

    void WaitRes()
    {
        PlayerData.Instance.WaitCollectRes();
        UIEvent.getInstance().nodeRefreshEvent.Invoke();
    }

	public override string path ()
	{
		return "UIDialog/UIMain";
	}

	public override string panal()
	{
		return UIManager.panelLayerName.root.ToString();
	}
}
